
const app = getApp()
const $api = require('../../../utils/api.js').API;

Page({
    data: {
        page: 1,
        noneShow:false,
        select_true1:true,
        select_true2:false,
        list:[],
        dataType:1,//商品
        page:1,
        pageShow:true,
        puid:0,
        uid:wx.getStorageSync('uid'),
        total:{},
        shareTotal:[],
        keyword:''
    },
    onLoad:function(){
        wx.showLoading()
        this.getlist();
        this.getCount();
        this.getTotal();
    },
    getTotal:function(){
        var that = this
        var data = {'uid':wx.getStorageSync('uid')}
        $api.get('user/getShareCount',data).then(res => {
            if(res.data.code == 1){
                that.setData({
                    shareTotal:res.data.data
                })
            }
        })
    },
    getCount:function(){
        var that = this
        var data = {'uid':wx.getStorageSync('uid')}
        $api.get('member/teamCount',data).then(res => {
            if(res.data.code == 1){
                that.setData({
                    total:res.data.data
                })
            }
        })
    },
    getlist: function(){
        var that = this
        //wx.setStorageSync('uid',3)
        var data ={'uid':wx.getStorageSync('uid'),
            'type':this.data.dataType,
            'page':this.data.page,
            'puid':this.data.puid,
            'keyword':this.data.keyword
        }
        var list = this.data.list
        $api.get('member/myTeam',data).then(res => {
            if(res.data.code == 1){
                if(res.data.data.data.length == 0){
                    that.setData({
                        noneShow:true
                    })
                }else{
                    that.setData({
                        noneShow:false
                    })
                }
                if(res.data.data.last_page <= that.data.page){
                    that.setData({
                        pageShow:false
                    })
                }
                wx.hideLoading()
                if(that.data.page == 1){
                    that.setData({
                        list:res.data.data.data
                    })
                }else{
                    that.setData({
                        list:list.concat(res.data.data.data)
                    })
                }
            }
        }).catch(err => {
            //请求失败
            //console.log('error',err);
        })
    },
    selectCate:function(e){
        var ii = e.currentTarget.dataset.index;
        var type = 'select_true'+ii
        this.setData({
            dataType:ii,
            page:1,
            pageShow:true,
            select_true1:false,
            select_true2:false,
            puid:0
        });
        this.setData({
            [type]:true
        })
        wx.showLoading()
        this.getlist()
    },
    onReachBottom: function(t){
        if(this.data.pageShow){
            //当前不是最后一页可加载
            this.setData({
                page: this.data.page + 1,
            })
        wx.showLoading()
        this.getlist();
        }
    },
    myShare:function(e){
        if(this.data.dataType == 1){
            var count = e.currentTarget.dataset.count
            if(count <= 0){
                wx.showToast({
                    title:'此用户暂无推荐人!!',
                    duration:1000,//显示时长
                    mask:true,//是否显示透明蒙层，防止触摸穿透，默认：false  
                    icon:'none', //图标，支持"success"、"loading" 
                })
                return;
            }
            this.setData({
                select_true1:false,
                select_true2:true,
                puid:e.currentTarget.dataset.id,
                dataType:2,
                page:1,
                pageShow:true
            });
            wx.showLoading()
            this.getlist();
        }
    },
    search:function(e){
        this.setData({
            keyword:e.detail.value
        })
        wx.showLoading()
        this.getlist()
    },
    onShareAppMessage: function() {
        return {
            title: "天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
      }
});